package denglu; /**
 * Created by ECHO on 2018/7/30.
 */
import denglu.Dao.UserDAO;
import denglu.utity.User;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
//事务控制
@Transactional
public class denglutest {

    @Autowired
    private UserDAO userdao;

    @Test
    //设置回滚为关闭
    @Rollback(false)
    public void testUserMapper() throws Exception {
        //通过详细信息直接添加
        userdao.insert("RO635","USA",730);
        //通过id查询获取对象
        User uuu = userdao.findById(4);
        //更新对象的国籍
        uuu.setCountry("U.S.A");
        //更新
        userdao.update(uuu);
        //通过id删除
        userdao.delete(uuu.getId());
        //创建新对象
        uuu = new User("ro635", "USA",730);
        //通过对象添加
        userdao.insertByUser(uuu);
        //通过map创建对象和添加
        Map<String, Object> map = new HashMap<>();
        map.put("name", "UMP45");
        map.put("country", "GER");
        map.put("length",695);
        userdao.insertByMap(map);
    }
}
